﻿@namespace BlazorComponent
@inherits BDomComponentBase
@typeparam TItem

@if (RealDisplay)
{
    <CascadingValue Value="this" Name="SelfNode">
        <div @key="NodeId" class="@CssProvider.GetClass(this)" style="@CssProvider.GetStyle(this)">
            @for (int i = 0; i < TreeLevel; i++)
        {
            <div class="@CssProvider.GetClass(this,"level")"></div>
        }

        <div style="@CssProvider.GetStyle(this,"icon")">
            @if (!IsLeaf)
            {
                <i Class="mr-3 fas @((HasChildNodes && Expanded) ? "fa-caret-down" : "fa-caret-right")" @onclick="@(() => Expanded = !Expanded)"></i>
            }
        </div>

        @if (Checkable)
        {
            <i Class="mr-3 far @(Checked ? "fa-check-square" : "fa-square")" @onclick="OnCheckBoxClick"></i>
        }

        <span style="@CssProvider.GetStyle(this,"title")" @onclick="async ()=> { if (HandleItemClick.HasDelegate) await HandleItemClick.InvokeAsync(DataItem);}">
            @Title
        </span>
    </div>
</CascadingValue>
}

<CascadingValue Value="this" Name="Node">
    @if (DataItem != null)
    {
        foreach (var item in ChildDataItems)
        {
            <SlotComponent DataItem="@item" @key="item.GetHashCode()" Description="SlotProvider.GetSlot<BTreeItem<TItem>>()"></SlotComponent>
        }
    }
    else
    {
        @Nodes
    }
</CascadingValue>